<script type="text/javascript">
	$(function(){
		$('#dg').edatagrid({
			url: 'order/list'
		});
		/* bao cao  */
	$("#click-order").click(function () {
       $('#dlg-order').dialog('open').dialog('setTitle','Lựa chọn thời gian xuất báo cáo');	
	    $('#fm-order').form('clear');	
    });	  	
	/* het bao cao  */
	
	});
	function add() {
		window.location = '/order/new';
	}
	function edit() {
		var row = $('#dg').datagrid('getSelected');
		window.location = '/order/edit?id='+row.id;
	}
	function del() {
		var row = $('#dg').datagrid('getSelected');
		if(row) {
			$.messager.confirm('Thông báo','Bạn có chắc chắn muốn xóa?',function(r){
				if (r){
					$.ajax({
						url: 'order/delete?id=' + row.id,
						success: function() {
							$('#dg').datagrid('reload');
						}
					});
				}
			});
		}
	}
	function searchOrder() {
		var kw = $('#kw').val();
		var d = $('input[name=date]').val();
		$('#dg').datagrid('load', {kw: kw, d: d});
	}
	
	function formatPayment(val, row) {
		if(parseInt(val)) {
			return 'Đã thanh toán';
		} else {
			return 'Chưa thanh toán';
		}
	}
	
	
function export_excel()
{	
	var s = $('#starday').datebox('getValue');
	var e = $('#endday').datebox('getValue');
	window.location.href = "/baocao/danhsachno?startday="+ s +"&&endday="+e;
		$('#dlg-order').dialog('close');
	return ;

}
	
</script>
<!-- Begin Datagrid -->
<table id="dg" title="Quản lý đơn hàng" style="width: 100%;"
	toolbar="#toolbar" pagination="true" idField="id" rownumbers="true"
	fitColumns="false" singleSelect="true" nowrap="true"
	data-options="border:false,fit:true">
	<thead>
		<tr>
			<th field="customerName" width="120" sortable="true">Khách hàng</th>
			<th field="customerPassport" width="150" sortable="true">CMND/Hộ chiếu</th>
			<th field="description" width="150" sortable="true">Mô tả</th>
			<th field="dates" width="150" sortable="true">Ngày</th>
			<th field="total" width="150" formatter="formatPrice">Tổng tiền</th>
			<th field="payment" width="150" formatter="formatPayment">Thanh toán</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding: 5px; height: auto;">
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
		onclick="add()">Thêm</a> <a href="#" class="easyui-linkbutton"
		iconCls="icon-edit" plain="true" onclick="edit()">Sửa</a> <a href="#"
		class="easyui-linkbutton" iconCls="icon-remove" plain="true"
		onclick="del()">Xóa</a>
		
		<!-- Bao cao -->
		<div style="float: right;">
		<a href="#" class="easyui-linkbutton" iconCls="icon-print" plain="true" id = "click-order" >Báo cáo Đơn hàng</a>
	   </div>
	   <!-- baocao -->
	   
	<!-- Begin Search -->
	<div id="search" style="padding: 3px">
		<span>Từ khóa:</span> <input id="kw" name="kw"
			style="line-height: 18px; border: 1px solid #ccc"> <span>Ngày:</span>
		<input id="date" name="date" class="easyui-datebox"
			style="line-height: 18px; border: 1px solid #ccc">
		<a href="#" class="easyui-linkbutton" iconCls="icon-search"
			plain="true" onclick="searchOrder()">Tìm kiếm</a>
	</div>
	<!-- End Search -->
</div>
<!-- End DataGrid -->

<!-- bao cao -->
<div id="dlg-order" class="easyui-dialog"
	style="width: 400px; height: 135px; background: #e7e7ef; padding: 15px;"
	modal="true" closed="true" buttons="#dlg-buttons-order">
	<form id="fm-order" method="post">
		<table border="0" width="auto" cellspacing="0" cellpadding="4"
			class="tblForm">
			       <tr>
					<td>
						<span>Từ:</span>
					</td>
					<td>
						<input id="starday" name="starday"  class="easyui-datebox" style="border: 1px solid #ccc">
					</td>
					<td><span>Đến:</span></td>
					<td>
						<input id="endday" name="endday" class="easyui-datebox" >
					</td>
			</tr>
		</table>
	</form>
</div>

<div id="dlg-buttons-order">
	<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
		onclick="export_excel()">Xuất file</a> <a href="#"
		class="easyui-linkbutton" iconCls="icon-cancel"
		onclick="javascript:$('#dlg-order').dialog('close')">Hủy bỏ</a>
</div>
<!-- het bao cao -->